/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.order.remote.RemoteServiceOrderServiceImpl
   Module Description   :

   Date Created      : 2010/2/4
   Original Author   : andy.chuang
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.order.remote;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;

import com.yaodian100.core.common.service.BaseManager;
import com.yaodian100.core.common.utils.StringUtils;
import com.yaodian100.ec.member.service.MemberService;
import com.yaodian100.ec.order.entity.InboundTrackingCase;
import com.yaodian100.ec.order.entity.ServiceOrders;
import com.yaodian100.ec.order.service.ServiceOrderService;

/**
 * @author andy.chuang
 * 
 */
public class RemoteServiceOrderServiceImpl implements RemoteServiceOrderService {
	@Autowired
	private BaseManager baseMgr;
	@Resource
	private MemberService memberService;
	@Resource
	private ServiceOrderService serviceOrderService;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.yaodian100.ec.order.remote.RemoteServiceOrderService#updateServiceOrderStatus(com.yaodian100.ec.order.remote
	 * .ServiceOrderBo)
	 */
	@Override
	public String updateServiceOrderStatus(ServiceOrderBo sob) {
		try {
			serviceOrderService.updateServiceOrderStatus(sob);
			return "true";
		} catch (Exception e) {
			String execLog = StringUtils.printExecption(null, e);
			return execLog;
		}
	}

	public String returnShipFare(String trxType, String memberId, String trxTypeId, float trxAmount, Date trxDate,
			String description, String jobId, Date refundDate) {

		try {
			serviceOrderService.returnShipfare(trxType, memberId, trxTypeId, trxAmount, trxDate, description, jobId,
					refundDate);
		} catch (Exception e) {
			String execLog = StringUtils.printExecption(null, e);
			return execLog;
		}
		return "true";
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.yaodian100.ec.order.remote.RemoteServiceOrderService#delServiceOrder(java.lang.String)
	 */
	@Override
	public String delServiceOrder(String serviceId) {
		if (StringUtils.isNotBlank(serviceId)) {
			ServiceOrders so = serviceOrderService.get(serviceId);
			if (so != null) {
				serviceOrderService.delete(so);
			} else {
				// so 已删除
				return "true";
			}
		} else {
			return "false";
		}
		return "true";
	}

	@Override
	public String updateInboundTrackingCaseStatus(String caseId, String orderId, String serviceOrderId,
			String isReceivePackage, String isQc, String isShip, String isArrival, String isRefund) {
		Map<String, Object> trackCaseMap = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(caseId)) {
			trackCaseMap.put("caseId", caseId);
		}
		if (StringUtils.isNotBlank(orderId)) {
			trackCaseMap.put("orderId", orderId);
		}
		if (StringUtils.isNotBlank(serviceOrderId)) {
			trackCaseMap.put("serviceOrderId", serviceOrderId);
		}
		List<InboundTrackingCase> inboundTrackingCaseList = serviceOrderService.getInboundTrackingCase(trackCaseMap);
		if (inboundTrackingCaseList.size() > 0) {
			InboundTrackingCase inboundTrackingCase = inboundTrackingCaseList.get(0);
			inboundTrackingCase.setIsReceivePackage(isReceivePackage);
			inboundTrackingCase.setIsQc(isQc);
			inboundTrackingCase.setIsShip(isShip);
			inboundTrackingCase.setIsArrival(isArrival);
			inboundTrackingCase.setIsRefund(isRefund);
			serviceOrderService.saveOrUpdateInboundTrackingCase(inboundTrackingCase);
			return "true";
		} else {
			return "false";
		}
	}

}
